package com.lifeservice.console.controller;

import com.lifeservice.common.annotation.Log;
import com.lifeservice.common.core.controller.BaseController;
import com.lifeservice.common.core.domain.AjaxResult;
import com.lifeservice.common.core.page.TableDataInfo;
import com.lifeservice.common.enums.BusinessType;
import com.lifeservice.common.utils.poi.ExcelUtil;
import com.lifeservice.console.domain.LifeWxappConfig;
import com.lifeservice.console.service.ILifeWxappConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信配置Controller
 *
 * @author lifeservice
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/console/config")
public class LifeWxappConfigController extends BaseController {
    @Autowired
    private ILifeWxappConfigService lifeWxappConfigService;

    /**
     * 查询微信配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LifeWxappConfig lifeWxappConfig) {
        startPage();
        List<LifeWxappConfig> list = lifeWxappConfigService.selectLifeWxappConfigList(lifeWxappConfig);
        return getDataTable(list);
    }

    /**
     * 导出微信配置列表
     */
    @Log(title = "微信配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeWxappConfig lifeWxappConfig) {
        List<LifeWxappConfig> list = lifeWxappConfigService.selectLifeWxappConfigList(lifeWxappConfig);
        ExcelUtil<LifeWxappConfig> util = new ExcelUtil<LifeWxappConfig>(LifeWxappConfig.class);
        util.exportExcel(response, list, "微信配置数据");
    }

    /**
     * 获取微信配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lifeWxappConfigService.selectLifeWxappConfigById(id));
    }

    /**
     * 新增微信配置
     */
    @Log(title = "微信配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeWxappConfig lifeWxappConfig) {
        return toAjax(lifeWxappConfigService.insertLifeWxappConfig(lifeWxappConfig));
    }

    /**
     * 修改微信配置
     */
    @Log(title = "微信配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeWxappConfig lifeWxappConfig) {
        return toAjax(lifeWxappConfigService.updateLifeWxappConfig(lifeWxappConfig));
    }

    /**
     * 删除微信配置
     */
    @Log(title = "微信配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(lifeWxappConfigService.deleteLifeWxappConfigByIds(ids));
    }
}
